﻿using System.Data;
using System.Data.SQLite;

namespace Infrastructure.Common.Data
{
    public interface IDbHelper
    {
        /// <summary>
        ///     一个有效的数据库连接对象
        /// </summary>
        /// <returns></returns>
        SQLiteConnection GetConnection();

        /// <summary>
        ///     一个有效的数据库事务连接对象
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        SQLiteTransaction GetTransaction();

        bool ExecuteCommand(string text);

        /// <summary>
        ///     执行提条sql命令查询
        /// </summary>
        /// <param name="text"></param>
        DataSet ExecuteQuery(string text);

        /// <summary>
        ///     执行指定数据库连接对象的命令,返回DataSet.
        /// </summary>
        /// <remarks>
        ///     示例:
        ///     DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure, "GetOrders");
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="commandType">命令类型 (存储过程,命令文本或其它)</param>
        /// <param name="commandText">存储过程名或T-SQL语句</param>
        /// <returns>返回一个包含结果集的DataSet</returns>
        DataSet ExecuteDataset(SQLiteConnection connection, CommandType commandType, string commandText);

        /// <summary>
        ///     执行指定数据库连接对象的命令
        /// </summary>
        /// <remarks>
        ///     示例:
        ///     int result = ExecuteNonQuery(conn, CommandType.StoredProcedure, "PublishOrders");
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="commandType">命令类型(存储过程,命令文本或其它.)</param>
        /// <param name="commandText">存储过程名称或T-SQL语句</param>
        /// <returns>返回影响的行数</returns>
        int ExecuteNonQuery(SQLiteConnection connection, CommandType commandType, string commandText);

        /// <summary>
        ///     执行带事务的SQLiteCommand.
        /// </summary>
        /// <remarks>
        ///     示例.:
        ///     int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders");
        /// </remarks>
        /// <param name="transaction">一个有效的数据库连接对象</param>
        /// <param name="commandType">命令类型(存储过程,命令文本或其它.)</param>
        /// <param name="commandText">存储过程名称或T-SQL语句</param>
        /// <returns />
        /// 返回影响的行数/returns>
        int ExecuteNonQuery(SQLiteTransaction transaction, CommandType commandType, string commandText);

        /// <summary>
        ///     执行指定数据库连接对象的数据阅读器.
        /// </summary>
        /// <remarks>
        ///     示例:
        ///     SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure, "GetOrders");
        /// </remarks>
        /// <param name="connection">一个有效的数据库连接对象</param>
        /// <param name="commandType">命令类型 (存储过程,命令文本或其它)</param>
        /// <param name="commandText">存储过程名或T-SQL语句</param>
        /// <returns>返回包含结果集的SqlDataReader</returns>
        SQLiteDataReader ExecuteReader(SQLiteConnection connection, CommandType commandType, string commandText);
    }
}